<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Retrieve fingerprint of remote server</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.ssh2-fingerprint" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ssh2_fingerprint</h1>
  <p class="verinfo">(PECL ssh2 &gt;= 0.9.0)</p><p class="refpurpose"><span class="refname">ssh2_fingerprint</span> &mdash; <span class="dc-title">Retrieve fingerprint of remote server</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ssh2-fingerprint-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>ssh2_fingerprint</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$session</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = SSH2_FINGERPRINT_MD5 | SSH2_FINGERPRINT_HEX</span></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   Returns a server hostkey hash from an active session.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ssh2-fingerprint-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">session</code></dt>

     <dd>

      <p class="para">
       An SSH connection link identifier, obtained from a call to
       <span class="function"><a href="ssh2_connect.html" class="function">ssh2_connect()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">flags</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">flags</code> may be either of
       <strong><code>SSH2_FINGERPRINT_MD5</code></strong> or
       <strong><code>SSH2_FINGERPRINT_SHA1</code></strong> logically ORed with
       <strong><code>SSH2_FINGERPRINT_HEX</code></strong> or
       <strong><code>SSH2_FINGERPRINT_RAW</code></strong>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ssh2-fingerprint-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the hostkey hash as a string.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ssh2-fingerprint-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5618">
    <p><strong>Example #1 Checking the fingerprint against a known value</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$known_host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'6F89C2F0A719B30CC38ABDF90755F2E4'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$connection&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ssh2_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'shell.example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">22</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$fingerprint&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ssh2_fingerprint</span><span style="color: #007700">(</span><span style="color: #0000BB">$connection</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">SSH2_FINGERPRINT_MD5&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">SSH2_FINGERPRINT_HEX</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">$fingerprint&nbsp;</span><span style="color: #007700">!=&nbsp;</span><span style="color: #0000BB">$known_host</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;die(</span><span style="color: #DD0000">"HOSTKEY&nbsp;MISMATCH!\n"&nbsp;</span><span style="color: #007700">.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"Possible&nbsp;Man-In-The-Middle&nbsp;Attack?"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>